<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>添加管理员</title>
    <link rel="stylesheet" href="/asset/layui/css/layui.css">
    <link rel="stylesheet" href="/asset/css/index.css">
    <link rel="Shortcut Icon" href="cachet.ico">
    <script type="text/javascript" src="/asset/js/jquery-3.3.1.min.js"></script>
	<script src="/asset/layui/layui.js"></script>
    <script src="/asset/js/common.js"></script>
</head>
<body >
<div class="alert_bigbox">

	<form class="layui-form">
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>登陆账户
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="username" name="username" required="" lay-verify="username" autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>登陆账户由6-18英文数字组成
              </div>
          </div>
          
          <div class="layui-form-item">
              <label for="password" class="layui-form-label">
                  <span class="x-red">*</span>登陆密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="password" name="password" required="" lay-verify="password" autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">6-18个字符 </div>
          </div>
          <div class="layui-form-item">
              <label for="repassword" class="layui-form-label">
                  <span class="x-red">*</span>确认密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="repassword" name="repassword"  required="" lay-verify="repassword" autocomplete="off" class="layui-input">
              </div>
          </div>
          <hr>
          <div class="layui-form-item">
              <label for="name" class="layui-form-label">
                  <span class="x-red">*</span>姓名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="name" name="name" value="" required="" lay-verify="name" autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="gender" class="layui-form-label">
                  <span class="x-red">*</span>性别
              </label>
              <div class="layui-input-block">
                  <input type="radio" name="gender" value="MALE" title="男">
				  <input type="radio" name="gender" value="FEMALE" title="女">
				  <input type="radio" name="gender" value="UNKNOWN" title="未知" checked>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="mobile" class="layui-form-label">
                  <span class="x-red">*</span>手机号码
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="mobile" name="mobile" value="" required="" lay-verify="mobile" autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="roleId" class="layui-form-label">
                  <span class="x-red">*</span>授权角色
              </label>
              <div class="layui-input-inline">
                  <select id="roleId" name="roleId" class="valid">
                  	<#list roles as item>
                    <option value="${item.roleId}">${item.roleName}</option>
                    </#list>
                  </select>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">增加</button>
          </div>
      </form>

</div>

    <script>
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
        
          //自定义验证规则
          form.verify({
            username: function(value){
              if(value.length < 5){
                return '登陆账户至少得5个字符啊';
              }
            }
            ,password: [/(.+){6,12}$/, '密码必须6到12位']
            ,repassword: function(value){
                if($('#password').val()!=value){
                    return '两次密码不一致';
                }
            }
          });

          //监听提交
          form.on('submit(add)', function(data){
            $.ajax({
      			type:"POST", 
      			url:"/admin/operator/create.htm",
      			data:data.field,
      			success:function(result) {
		      
		      		if(result.code=='1'){
		      			layer.alert("增加成功", {icon: 6},function () {
			                // 获得frame索引
			                 window.parent.location.reload();
			                var index = parent.layer.getFrameIndex(window.name);
			                //关闭当前frame
			                parent.layer.close(index);
			            });
		      		}else{
		      		 	layer.msg(result.msg);
		      		}
		      
		    	 	} 
		    }); 
            
            
            
            return false;
          });
          
        });
    </script>

</body>
</html>